home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1990: Night of the Living Disc / Night of the Living Disc.2mg / Dev.CD.5 / Tools / File.Type.Notes / FTN.E0.8002.3 < prev    next >
Encoding:
Text File  |  1990-03-03  |  21.4 KB  |  421 lines  |  [04] ASCII Text (0x0000)

  1. Apple II
  2. File Type Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6. File Type:         $E0 (224)
  7. Auxiliary Types:   $0002 & $0003
  8.  
  9. Full Name:     AppleDouble Header File (Auxiliary Type $0002)
  10.                AppleDouble Data File (Auxiliary Type $0003)
  11. Short Name:    AppleDouble Header (Auxiliary Type $0002)
  12.                AppleDouble Data (Auxiliary Type $0003)
  13.  
  14. Revised by:    Matt Deatherage                                     March 1990
  15. Written by:    Matt Deatherage                                     March 1989
  16.  
  17. Files of these types and auxiliary types contain file data in AppleDouble 
  18. format.
  19. Changes since March 1989:  Clarified the Real Name entry field.
  20. _____________________________________________________________________________
  21.  
  22. AppleDouble is one of two standards (the other is AppleSingle) put forth by 
  23. Apple Computer, Inc. for representing files on foreign file systems while 
  24. preserving all attributes of the file's home system on file systems that do 
  25. not support the same attributes.
  26.  
  27. Experience indicated that a single format would be inadequate to cover all 
  28. cases.  Two closely related formats, however, can serve most needs.  Although 
  29. the primary impetus for developing these formats is storing extended files 
  30. (files with both resource and data forks) on file systems that do not support 
  31. the notion of two forks, the proposed formats are general enough that they can 
  32. be used to represent a file from any file system on any other file system.
  33.  
  34. AppleDouble keeps the data fork as a separate file from the file attributes 
  35. and the resource fork, and this Note describes this file format.  AppleSingle 
  36. keeps all attributes and the contents of both forks in a single file in the 
  37. foreign file system, and is described in the File Type Note for File Type $E0, 
  38. Auxiliary Type $0001.
  39.  
  40. AppleSingle is intended to be used primarily as a storage format, especially 
  41. for cases where you must store an extended file on a foreign file system and 
  42. later reconstruct the extended file.  AppleDouble is more appropriate for 
  43. applications where the users of the foreign file system might want to modify 
  44. the contents of the file.  Since most applications keep file data in the data 
  45. fork, AppleDouble format saves the contents of the data fork in one file.  All 
  46. other file attributes, including the resource fork, are kept in a separate 
  47. file.
  48.  
  49.  
  50. Reasons for Using AppleDouble
  51.  
  52. There are several reasons for supporting an interchange format between file 
  53. systems.  Perhaps the most germane is one of the least obvious:  handling 
  54. extended files on foreign file systems which do not support extended files.
  55.  
  56. For example, the ProDOS FST in GS/OS can create an extended file on a ProDOS 
  57. disk.  However, ProDOS 8 is unable to operate on the file, since it sees it as 
  58. having an unsupported storage type.  If a telecommunications program or other 
  59. utility capable of transferring files is operating under ProDOS 8 and attempts 
  60. to receive an extended file, it is unable to create the file.
  61.  
  62. At this point, the application could use READ_BLOCK and WRITE_BLOCK commands, 
  63. along with a knowledge of the ProDOS file system, to create the file on its 
  64. own.  However, this is strongly discouraged.  The ProDOS file system format 
  65. for extended files is not documented and could change in the future.  In 
  66. addition, the program could be running on a eight-bit system.  If the disk is 
  67. only used on an eight-bit system, the extended files would not only be 
  68. unwanted, but also unremovable without using the disk on an Apple IIGS or 
  69. later system running GS/OS.
  70.  
  71. However, if the application is aware of the AppleDouble format, it can quickly 
  72. store an extended file in AppleDouble, leaving the conversion back to the 
  73. extended file to GS/OS, or another operating system.  This is the recommended 
  74. way for ProDOS 8 applications to create and handle extended files.  Use either 
  75. AppleSingle or AppleDouble.
  76.  
  77.  
  78. AppleDouble Format
  79.  
  80. AppleDouble consists of two files, an AppleDouble Header File and an 
  81. AppleDouble Data File.  The AppleDouble Header file contains a header followed 
  82. by data.  The header consists of several fixed fields and a list of entry 
  83. descriptors, each pointing to an entry.  Apple defines these standard entries:  
  84. Resource Fork, Real Name (name in the home file system), Comment, Icon and 
  85. File Info.  Each entry is optional, so it may not appear in the file.  We also 
  86. define the new entry Data Pathname, pointing to the pathname of the 
  87. AppleDouble Data File.  The Header File has exactly the same format as an 
  88. AppleSingle file, except it has no data fork entry.  The AppleDouble Data File 
  89. consists of just the data fork of the file, with no extra header at all.
  90.  
  91. Note:  All numeric entries, including entries representing ProDOS data 
  92.        structures (such as file type and auxiliary type) are Reverse 
  93.        ordered.  This is provided so any host CPU can attempt to 
  94.        interpret entries in the header without having to know the 
  95.        standard byte-ordering of the home file system.  Therefore, in 
  96.        this Note you see descriptive entries like "Rev. 4 Bytes."  This 
  97.        serves as a reminder that all header fields are stored high byte 
  98.        first, even though the notation Bytes does not imply any specific 
  99.        ordering in other File Type Notes.
  100.  
  101. Also note that ASCII strings are not stored in reverse order, just non-ASCII 
  102. constants.
  103.  
  104. The Header in the Header File:
  105.  
  106. Magic Number         Rev. Long    The Magic Number field is modeled after 
  107.                                   the feature in UNIX.  It is intended to be 
  108.                                   used in whatever way the foreign file 
  109.                                   system distinguishes a file as AppleDouble 
  110.                                   format.  See the section "Identifying 
  111.                                   AppleDouble Files."  The Magic Number for 
  112.                                   AppleDouble format is $00051607, which is 
  113.                                   stored reverse as $00 $05 $16 $07 (reverse 
  114.                                   of normal 65816/6502 order).
  115. Version Number       Rev. Long    The version of AppleDouble format, in case 
  116.                                   the format evolves (more fields may be 
  117.                                   added to the header).  The version 
  118.                                   described here is $00010000, stored 
  119.                                   (reverse) as $00 $01 $00 $00.
  120.  
  121. Home File System     16 Bytes     A fixed-length, 16-byte ASCII string not 
  122.                                   preceded by a length byte, but possibly 
  123.                                   padded with blanks.  Apple has defined 
  124.                                   these values:
  125.                                   "ProDOS"    $50726F444F5320202020202020202020
  126.                                   "Macintosh" $4D6163696E746F736820202020202020
  127.                                   "MS-DOS"    $4D532D444F5320202020202020202020
  128.                                   "Unix"      $556E9878202020202020202020202020
  129.                                   "VAX VMS"   $56415820564D53202020202020202020
  130.                                   Apple welcomes suggestions for other file 
  131.                                   systems that should be included in this 
  132.                                   list.
  133. Number of entries    Rev. Word    Tells how many different entries are 
  134.                                   included in the file.  This unsigned 
  135.                                   reverse word may be zero.  If it is non-
  136.                                   zero, then that number of entry 
  137.                                   descriptors immediately follows this 
  138.                                   field.
  139.  
  140.  
  141. For Each Entry:
  142.  
  143. Entry ID             Rev. Long    Identifies the entry.  Apple has defined 
  144.                                   the following Entry IDs and their values:
  145.                                   1 = Data Fork
  146.                                   2 = Resource Fork
  147.                                   3 = Real Name (The file's name in the home 
  148.                                       file system)
  149.                                   4 = Comment* (standard Macintosh comment)
  150.                                   5 = Icon, B&W* (standard Macintosh black 
  151.                                       and white icon)
  152.                                   6 = Icon, Color* (reserved for Macintosh 
  153.                                       color icon)
  154.                                   7 = File Info (file attributes, dates, etc.)
  155.                                   9 = Finder Info* (standard Macintosh 
  156.                                       Finder Info)
  157.                                   Entry IDs marked with asterisks (*) are 
  158.                                   not used for most files created under 
  159.                                   ProDOS or GS/OS.  Furthermore, icon 
  160.                                   entries probably do not appear in most 
  161.                                   files since they are typically stored as a 
  162.                                   bundle in the application file's resource 
  163.                                   fork on the Macintosh.  Apple reserves the 
  164.                                   range of Entry IDs from $0 to $7FFFFFFF 
  165.                                   for future use.  The rest of the range is 
  166.                                   available for other systems to define 
  167.                                   their own entries.  Apple does not 
  168.                                   arbitrate the use of the rest of the 
  169.                                   range.
  170.                                   Descriptions of the standard entries are 
  171.                                   given below.
  172. Offset               Rev. Long    An unsigned reverse long which indicates 
  173.                                   the byte offset from the start of the file 
  174.                                   to the start of the entry.
  175. Entry Length         Rev. Long    An unsigned reverse long which indicates 
  176.                                   the length of the entry in bytes.  The 
  177.                                   length may be zero.
  178.  
  179.  
  180. Standard Entries:
  181.  
  182. The Real Name Entry:
  183.  
  184. The Real Name entry indicates the file's original filename in the host file 
  185. system.  This is not a Pascal or C string; it is just ASCII data.  The length 
  186. is indicated by the Entry Length field for the Real Name entry.
  187.  
  188. The File Info Entry:
  189.  
  190. The File Info entry (Entry ID = 7) is different for each home file system.  
  191. For ProDOS files, the entry is 16 bytes long and consists of the creation date 
  192. and time and the modification date and time in ProDOS 8 (ProDOS 16/class zero 
  193. GS/OS) form, the access word, a two-byte file type and four-byte auxiliary 
  194. type.  This is detailed in standard format below, along with defined File Info 
  195. entries for some other file systems.
  196.  
  197. ProDOS:
  198.  
  199. Create Date         Rev. 2 Bytes  Creation date packed into standard 
  200.                                   ProDOS 8 format.
  201. Create Time         Rev. 2 Bytes  Creation time packed into standard 
  202.                                   ProDOS 8 format.
  203. Modification Date   Rev. 2 Bytes  Modification date packed into 
  204.                                   standard ProDOS 8 format.
  205. Modification Time   Rev. 2 Bytes  Modification time packed into 
  206.                                   standard ProDOS 8 format.
  207. Access              Rev. Word     The file's access.  This may be used 
  208.                                   directly in ProDOS 16 or GS/OS calls; only 
  209.                                   the low byte is significant to ProDOS 8.
  210. File Type           Rev. Word     The file type of the original file.  Only 
  211.                                   the low byte is significant to ProDOS 8.
  212. Auxiliary Type      Rev. Long     The auxiliary type of the original file.  
  213.                                   Only the low word is significant to ProDOS 8.
  214.  
  215. Note:  Although the ProDOS Access field, File Type and Auxiliary Type are 
  216.        the same length as found in ProDOS 16 and GS/OS structures, the 
  217.        Create and Modification Dates and Times are stored in two-byte 
  218.        (albeit byte-reversed) ProDOS 8 format, not eight-byte Apple IIGS 
  219.        format.
  220.  
  221. Macintosh:
  222.  
  223. Create Date         Rev. Long     Unsigned number of seconds between 
  224.                                   January 1, 1904, and the creation time of 
  225.                                   this file.
  226. Modification Date   Rev. Long     Unsigned number of seconds between 
  227.                                   January 1, 1904, and the last modification 
  228.                                   of this file.
  229. Last Backup Date    Rev. Long     Unsigned number of seconds between 
  230.                                   January 1, 1904, and the last backup time 
  231.                                   of this file.
  232. Attributes          Rev. Long     32 boolean flags.  Once the bytes are 
  233.                                   unreversed, bit zero is the locked bit and 
  234.                                   bit one is the protected bit.
  235.  
  236. MS-DOS:
  237.  
  238. Modification Date    Rev. 4 Bytes  MS-DOS format modification date.
  239. Attributes           Rev. 2 Bytes  MS-DOS attributes.
  240.  
  241. Unix:
  242.  
  243. Create Date/Time       Rev. 4 Bytes  Unix creation date and time.
  244. Last Use Date/Time     Rev. 4 Bytes  Unix time for the last 
  245.                                      time this file was used.
  246. Last Mod. Date/Time    Rev. 4 Bytes  Unix time for the last 
  247.                                      time this file was modified.
  248.  
  249.  
  250. The Finder Info Entry:
  251.  
  252. The Finder Info entry (Entry ID = 9) is for files where the host file system 
  253. is Macintosh.  It consists of 16 bytes of Finder Info followed by 16 bytes of 
  254. Extended Finder Info.  These are the fields ioFlFndrInfo followed by 
  255. ioFlXFndrInfo, as described in Inside Macintosh, Volume IV-183.  Newly created 
  256. files have zeroes in all Finder Info subfields.  If you are creating an 
  257. AppleDouble file whose home system is Macintosh, you may zero all unknown 
  258. fields, but you may want to set the fdType and fdCreator subfields.
  259.  
  260.  
  261. The Data Pathname Entry:
  262.  
  263. The Data Pathname entry (Entry ID = 100) is defined for the first time in this 
  264. Note.  It consists of a class one GS/OS input string noting the pathname of 
  265. the AppleDouble Data File as originally created:
  266.  
  267. Path Length    Rev. Word    The length of the pathname.
  268. Pathname       Bytes        ASCII pathname of the AppleDouble Data File 
  269.                             when created.
  270.  
  271. For strategies on using this segment (or not using it) to find the AppleDouble 
  272. Data File, see the section "Finding the AppleDouble Data File."
  273.  
  274.  
  275. The Entries in the Header File:
  276.  
  277. The entries themselves follow the header field and the entry descriptors.  The 
  278. actual data representing each entry must be in a single, contiguous block.  
  279. The offset field in that entry's descriptor points to it.  The entries could 
  280. appear in any order, but since the data fork is the entry that is most 
  281. commonly extended, Apple strongly recommends that the data fork always be kept 
  282. last in the file to facilitate its extension.  Apple also recommends that 
  283. those entries that are most often read, such as Real Name, File Info (and 
  284. Finder Info if present) be kept as close as possible to the header to maximize 
  285. the probability that a read of the first few blocks of the file retrieves 
  286. these entries.
  287.  
  288. It is possible to have holes in the file (unused space between entries).  To 
  289. find the holes, you must take the list of entry descriptors and sort them into 
  290. increasing offset order.  If the offset field of an entry is greater than the 
  291. offset plus the length of the previous entry (sorted), then a hole exists 
  292. between the entries.  You can make use of such holes; for example, if a file's 
  293. comment is ten bytes long, you could create a hole of 190 bytes after the 
  294. comment field to easily allow for the comment to later expand to its maximum 
  295. length of 200 bytes.  Because an AppleDouble file may contain holes, you must 
  296. find each entry by getting its offset from its entry descriptor, not by 
  297. assuming that it begins after the previous entry.
  298.  
  299. Byte ordering in file header fields follows 68000 convention, and each header 
  300. field has been so noted by the Reverse operator.
  301.  
  302.  
  303. The AppleDouble Data File
  304.  
  305. The AppleDouble Data File is simply the data fork of the original file 
  306. contained in a file of its own.  You may create it with a File Type and 
  307. Auxiliary Type assignment best suited to it, if desired.  For example, if the 
  308. program creating the AppleDouble Data File knows that the data fork contains 
  309. strictly ASCII text, it could create the file with File Type $04 (Text File) 
  310. so that other applications can deal with it accordingly.
  311.  
  312. If the creating program wishes to make no assumptions about the content of the 
  313. data fork, it is encouraged to create the AppleDouble Data File with file type 
  314. $E0 and auxiliary type $0003.  This identifies the file as an AppleDouble Data 
  315. File.
  316.  
  317.  
  318. Identifying AppleDouble Files
  319.  
  320. As this is an interchange format, from a ProDOS directory entry there is no 
  321. way to guarantee which files are AppleDouble files.  Apple has allocated File 
  322. Type $E0, Auxiliary Type $0002 for files which are AppleDouble Header Files, 
  323. and File Type $E0, Auxiliary Type $0003 for files which are AppleDouble Data 
  324. Files.  We strongly encourage ProDOS 8 and GS/OS applications to use these 
  325. file type and auxiliary type assignments when creating AppleDouble files.
  326.  
  327. AppleDouble files which do not have file type $E0 and auxiliary type $0002 or 
  328. $0003 can most easily be identified by opening them and attempting to 
  329. interpret them.  If it is not an AppleDouble Header File, the Magic Number is 
  330. not contained in the first four bytes of the file.  The chances that the file 
  331. would begin with those four bytes and not be an AppleDouble Header File, on a 
  332. purely random basis, are 4,294,967,295 to 1.  The chances that both the Magic 
  333. Number and the Version bytes would be the same in a non-AppleSingle file are 
  334. roughly 1.8 x 10^19 to 1.
  335.  
  336.  
  337. Finding the AppleDouble Data File
  338.  
  339. Since the AppleDouble Data File can be stored anywhere, with any file type and 
  340. auxiliary type, a program may have to make an effort to find it.  We recommend 
  341. the following steps:
  342.  
  343. 1.  If the Data Pathname segment exists, use that pathname.  If the 
  344.     path specified in the segment does not exist, extract the file 
  345.     name from the end of the pathname and look in the current 
  346.     directory for that file name.
  347. 2.  If Step 1 does not find the file (or if the Data Pathname segment 
  348.     does not exist), perform the appropriate Home File System 
  349.     algorithm (described below) to generate the name of the 
  350.     AppleDouble Data File from the AppleDouble Header File.
  351. 3.  If none of the file names generated in Step 2 are found, ask the 
  352.     user where the AppleDouble Data File is located.
  353.  
  354.  
  355. Filename Conventions:
  356.  
  357. Apple proposes the following standard for identifying AppleDouble Header File 
  358. names and AppleDouble Data File names from the file's real name.
  359.  
  360. ProDOS:
  361.  
  362. To generate the AppleDouble Data File name, use character substitution or 
  363. deletion to remove illegal characters, and use truncation if necessary to 
  364. reduce the length of the name to two characters less than the maximum file 
  365. name length.  This would be a maximum of 13, since the maximum file name 
  366. length is 15.
  367.  
  368. To generate the AppleDouble Header File name, prefix the AppleDouble Data File 
  369. name with the characters "R." (uppercase R period).
  370.  
  371. For example, the file name "This is a Foo File" could translate to an 
  372. AppleDouble Data File Name of "THIS.IS.A.FOO."  The AppleDouble Header File 
  373. name would then be "R.THIS.IS.A.FOO."
  374.  
  375. Unix:
  376.  
  377. To generate the AppleDouble Data File name, use character substitution to 
  378. replace any illegal characters with an underscore (_).  Since different Unix 
  379. systems have different requirements on maximum file name length, do not 
  380. explicitly truncate the name to a specific length.  Rather, allow the 
  381. truncation to be done by the Unix functions create(), open(), etc.
  382.  
  383. To generate the AppleDouble Header File name, A/UX (Apple's implementation of 
  384. Unix for Macintosh computers) prefixes a percent sign (%) to the AppleDouble 
  385. Data File name.  If necessary, truncate the last character to keep the file 
  386. name within the legal length range.  Other Unix systems may prefix a directory 
  387. name (e.g., ".AppleDouble/") to the AppleDouble Data File name to create the 
  388. name of the AppleDouble Header File.  In this scheme, all AppleDouble Header 
  389. Files corresponding to AppleDouble Data files are kept together in a single 
  390. subdirectory.
  391.  
  392. MS-DOS:
  393.  
  394. To generate the AppleDouble Data File name, use character substitution or 
  395. deletion to remove illegal characters, and use truncation if necessary to 
  396. reduce the length of the name to eight characters.  Then add the MS-DOS 
  397. extension that is most appropriate to the file (such as "TXT" for a pure text 
  398. file).
  399.  
  400. To generate the AppleDouble Header File name, add the extension ".ADF" to the 
  401. eight-character file name.
  402.  
  403. In any instance, most programs probably wish to display the names being used 
  404. for both AppleDouble files, so that the user may keep track of them on disk.
  405.  
  406. AppleDouble name derivations will be defined for all other file systems of 
  407. interest.  This allows applications running on the foreign file system (and 
  408. users as well) to see easily which files are AppleDouble pairs.  Knowledgeable 
  409. users, if they know the derivation, could rename or move the files so as to 
  410. preserve the connection between the two.  However, there is no guaranteed way 
  411. to prevent one file of the pair from being inconsistently renamed, moved, or 
  412. deleted.
  413.  
  414.  
  415. Further Reference
  416. _____________________________________________________________________________
  417.   o  Inside Macintosh, Volume IV
  418.   o  ProDOS 8 Technical Reference Manual
  419.   o  GS/OS Reference, Volume I
  420.  
  421.